import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/component/app_bar/index.dart';

class CustomLayout extends StatelessWidget {
  const CustomLayout({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(title: 'CustomMultiChildLayout布局'),
      body: CustomMultiChildLayout(
        delegate: MyDelegate(),
        children: [
          LayoutId(
              id: 1,
              child: FlutterLogo(
                size: 100,
              )),
          LayoutId(
              id: 2,
              child: FlutterLogo(
                size: 200,
              )),
        ],
      ),
    );
  }
}

class MyDelegate extends MultiChildLayoutDelegate {
  late Size size1, sise2;
  @override
  void performLayout(Size size) {
    if (hasChild(1)) {
      size1 = layoutChild(
          1,
          BoxConstraints(
              minHeight: 100, minWidth: 100, maxHeight: 100, maxWidth: 100));
      positionChild(1, Offset.zero);
    }
    if (hasChild(2)) {
      sise2 = layoutChild(
          2,
          BoxConstraints(
              minHeight: 200, minWidth: 200, maxHeight: 200, maxWidth: 200));
      positionChild(2, Offset(size1.width, size1.height));
    }
  }

  @override
  bool shouldRelayout(covariant MultiChildLayoutDelegate oldDelegate) {
    return true;
  }
}
